//---------------------------------------------------------------------------------
// Copyright (c) 2011, Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------------

namespace Microsoft.Samples.ServiceBus.SilverlightChat.Models.ViewModels
{
    using System;
    using System.Windows;
    using Microsoft.Samples.ServiceBus.SilverlightChat.Models.Commands;

    /// <summary>
    /// Encapsulates the view model for the initial login window (where a username
    /// is entered) and exposes a Login Command which can initiate the login actions. 
    /// </summary>
    public class LoginWindowViewModel : DependencyObject
    {
        public static readonly DependencyProperty UserNameProperty =
            DependencyProperty.Register("UserName", typeof(string), typeof(LoginWindowViewModel), new PropertyMetadata("Bob"));

        private readonly LoginWindow window;
        private readonly LoginCommand loginCommand;

        public LoginWindowViewModel(LoginWindow window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            this.window = window;
            this.loginCommand = new LoginCommand(this);
        }

        public string UserName
        {
            get { return (string)GetValue(UserNameProperty); }
            set { SetValue(UserNameProperty, value); }
        }

        public LoginWindow Window
        {
            get { return this.window; }
        }

        public LoginCommand LoginCommand
        {
            get { return this.loginCommand; }
        }
    }
}
